package com.book.controller;


import com.book.pojo.Shoucang;
import com.book.result.Result;
import com.book.service.ShoucangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cxy
 * @since 2023-10-13 15:50:00
 */
@RestController
@RequestMapping("/shoucang")
public class ShoucangController {
    @Autowired
    private ShoucangService shoucangService;

    //读者对作品进行收藏  加入数据到收藏表
    //rid读者id  bid作品id  收藏榜进行重新排行
    @PostMapping("insertShoucang")
    public Result insertShoucang(@RequestParam Long rid, @RequestParam Long bid){
        int i = shoucangService.insertShoucang(rid, bid);
        return Result.OK().setData(i);
    }

    //读者对作品取消收藏  从收藏表删除对应数据
    //rid读者id  bid作品id   收藏榜进行重新排行
    @DeleteMapping("deleteShoucang")
    public Result deleteShoucang(@RequestParam Long rid, @RequestParam Long bid){
        shoucangService.deleteShoucang(rid,bid);
        return Result.OK();
    }

    //查看读者的作品收藏集
    @GetMapping("selectBidsByRid")
    public Result selectBidsByRid(@RequestParam Long rid){
        List<Long> bids = shoucangService.selectBidsByRid(rid);
        return Result.OK().setData(bids);
    }

    //查询每个作品的数量
    @GetMapping("selectBookNumByBid")
    public void selectBookNumByBid(@RequestParam Long bid){
        shoucangService.selectBookNumByBid(bid);
    }

    //收藏榜
    @GetMapping("CollectRanking")
    public  List<Shoucang> CollectRanking(){
       return shoucangService.CollectRanking();
    }
}
